package leetcode;



/**
 * @Classname RemoveElements_0203
 * @Author happytaohaha
 * @Date 2020/3/28
 * @Description TODO
 */
public class RemoveElements_0203 {

    public ListNode removeElements(ListNode head, int val) {
        //虚拟头节点
        ListNode dummyHead = new ListNode(0);
        dummyHead.next = head;
        ListNode cur = head;
        ListNode pre = dummyHead;
        while (cur!=null){
            if(cur.val ==val){
                pre.next = cur.next;
            }else{
                pre = cur;
            }
            cur = cur.next;
        }
        return dummyHead.next;
    }
}
